﻿#include "FITKAbaTimePoints.h"


bool Interface::FITKAbaTimePoints::copy(FITKAbstractDataObject *obj)
{
    FITKAbaTimePoints* tp = dynamic_cast<FITKAbaTimePoints*>(obj);
    if (tp == nullptr)
        return false;
    this->setDataObjectName(tp->getDataObjectName());
    m_specifyUsingDelimiters = tp->m_specifyUsingDelimiters;
    m_points = tp->m_points;
    m_datas = tp->m_datas;
    return true;
}

bool Interface::FITKAbaTimePoints::getSpecifyUsingDelimiters() const
{
    return m_specifyUsingDelimiters;
}

void Interface::FITKAbaTimePoints::setSpecifyUsingDelimiters(bool state)
{
    m_specifyUsingDelimiters = state;
}

int Interface::FITKAbaTimePoints::getNumberOfRows()
{
    if (m_specifyUsingDelimiters)
        return m_datas.size();
    else
        return m_points.size();
}

void Interface::FITKAbaTimePoints::setNumberOfRows(int rows)
{
    if (m_specifyUsingDelimiters)
        m_datas.resize(rows);
    else
        m_points.resize(rows);
}

double Interface::FITKAbaTimePoints::getPoint(int index)
{
    if (index >= 0 && index < m_points.size())
        return m_points.at(index);
    return 0.0;
}

void Interface::FITKAbaTimePoints::setPoint(double value, int index)
{
    if (index >= 0 && index < m_points.size())
        m_points[index] = value;
}

void Interface::FITKAbaTimePoints::insertPoint(double value, int index)
{
    m_points.insert(index, value);
}

double Interface::FITKAbaTimePoints::getStart(int index)
{
    if (index >= 0 && index < m_datas.size())
        return m_datas.at(index).at(0);
    return 0.0;
}

double Interface::FITKAbaTimePoints::getEnd(int index)
{
    if (index >= 0 && index < m_datas.size())
        return m_datas.at(index).at(1);
    return 0.0;
}

double Interface::FITKAbaTimePoints::getIncrement(int index)
{
    if (index >= 0 && index < m_datas.size())
        return m_datas.at(index).at(2);
    return 0.0;
}

void Interface::FITKAbaTimePoints::setStart(double value, int index)
{
    if (index >= 0 && index < m_datas.size())
        m_datas[index][0] = value;
}

void Interface::FITKAbaTimePoints::setEnd(double value, int index)
{
    if (index >= 0 && index < m_datas.size())
        m_datas[index][1] = value;
}

void Interface::FITKAbaTimePoints::setIncrement(double value, int index)
{
    if (index >= 0 && index < m_datas.size())
        m_datas[index][2] = value;
}

void Interface::FITKAbaTimePoints::insertRow(int index)
{
    if (m_specifyUsingDelimiters)
        if (index >= 0 && index <= m_datas.size())
            m_datas.insert(index, { 0.0,0.0,0.0 });
    else
        if (index >= 0 && index <= m_points.size())
        m_points.insert(index, 0.0);
}

void Interface::FITKAbaTimePoints::removeRow(int index)
{
    if (m_specifyUsingDelimiters)
    {
        if (index >= 0 && index < m_datas.size())
            m_datas.removeAt(index);
    }
    else
    {
        if (index >= 0 && index < m_points.size())
            m_points.removeAt(index);
    }
}

void Interface::FITKAbaTimePoints::clearData()
{
    if (m_specifyUsingDelimiters)
        m_datas.clear();
    else
        m_points.clear();
}
